<template>
  <PICpieChart :change="change" :title='title' :seriesData='seriesData' :horizontal="orientType" :height="height"/>
</template>

<script>
import PICpieChart from '@views/dashboard/components/PICpieChart'

export default {
  name: 'PICLoss',
  components:{
    PICpieChart,
  },
  props:{
    orientType:{
      type:Boolean,
      default:true
    },
    height:{
      type:String,
      default:'300px'
    },
    activePart:{
      type:String,
      default:''
    },
  },
  computed: {
    begindate () {
      return this.$store.state.app.begindate;　　//需要监听的数据
    },
    enddate () {
      return this.$store.state.app.enddate;　　//需要监听的数据
    },
    kjtext () {
      return this.$store.state.app.kjtext;　　//需要监听的数据
    },
    reSearch(){
      return this.$store.state.app.reSearch;　　//需要监听的数据
    }
  },
  watch:{
    activePart:{
      handler(){
        this.getChartData()
      }
    },
    begindate:{
      handler(newVal,oldVal){
        console.log('begindate',newVal)
        this.getChartData()
      }
    },
    enddate:{
      handler(newVal,oldVal){
        console.log('enddate',newVal)
      }
    },
    kjtext:{
      handler(newVal,oldVal){
        console.log('kjtext',newVal)
        this.getChartData()
      }
    },
    reSearch:{
      handler(newVal,oldVal){
        console.log('reSearch',newVal)
        this.getChartData()
      }
    }
  },
  data(){
    return {
      title:'PIC Loss Fail rate',
      seriesData:[],
      change:true
    }
  },
  methods:{
    getChartData(){
      this.$http.get('/inspect/reportapi/getPieData',{
        params:{
          line:this.activePart,
          begindate:this.begindate,
          enddate:this.enddate,
          kjtext:this.$store.state.app.kjtext,
          linecode:this.$store.state.app.linecode,
          procode:this.$store.state.app.procode,
        }
      }).then(res=>{
        if (res.success){
          this.seriesData = res.result
          this.change = !this.change
            // this.seriesData = [
            //   {value: 1048, name: '生产部'},
            //   {value: 735, name: '技术部'},
            //   {value: 580, name: '品质部'},
            //   {value: 484, name: 'ME工程部'},
            //   {value: 300, name: 'EE工程部'}
            // ]
        }else{
          this.$message.error(res.message)
        }
      });
    }
  },
  mounted() {
    this.getChartData()
  },
  // mounted() {
  //   this.seriesData = [
  //     {value: 1048, name: '生产部'},
  //     {value: 735, name: '技术部'},
  //     {value: 580, name: '品质部'},
  //     {value: 484, name: 'ME工程部'},
  //     {value: 300, name: 'EE工程部'}
  //   ]
  // }
}
</script>

<style scoped>

</style>